#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/9/6 15:52
# @Updatetime：15:52
# @Author：Test008
# @File：5-河南省疫情地图开发
# @Description：
# 1》读取数据
# 2》数据处理
# 3》地图导入数据
# 4》绘制地图，全局配置
import json

from pyecharts.charts import Map
from pyecharts.options import *

with open('../../../static/doc/yiqing_data/疫情.txt', 'r', encoding='utf-8') as f:
    json_data = f.read()
dict_data = json.loads(json_data)
henan_province_datas = dict_data['areaTree'][0]['children'][3]['children']

all_city_dict = []
for henan_data in henan_province_datas:
    city_name = henan_data['name'] + '市'
    city_confirm = henan_data['total']['confirm']
    all_city_dict.append((city_name, city_confirm))
all_city_dict.append(("济源市", 5))
map = Map()
map.add('各市疫情分布图', all_city_dict, '河南')
map.set_global_opts(
    title_opts=TitleOpts(title='2021年河南省各市疫情分布图'),
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True, pieces=[
            {"min": 0, "max": 25, "label": '0-25', "color": "#c4ccd3"},
            {"min": 25, "max": 50, "label": '25-50', "color": "#546570"},
            {"min": 50, "max": 100, "label": '50-100', "color": "#ef5b9c"},
            {"min": 100, "max": 500, "label": '100-500', "color": "#f05b72"}
        ]
    )
)
map.render('河南疫情分布图.html')
